from flask import Blueprint, request
from service.comment_service import CommentService
from utils.ResultUtil import Response
from model.comment import Comment
comment = Blueprint("comment", __name__, url_prefix="/comment")


@comment.route('/getComment', methods=['GET'])
def getComment():
    blog_id = request.args.get("blogId")
    return Response().success(CommentService().getComment(blog_id))

@comment.route('/count', methods=['GET'])
def countByBlogId():
    blog_id = request.args.get("blog_id")
    print(blog_id)
    return Response().success(CommentService().countByBlogId(blog_id))

@comment.route('/add',methods=['POST'])
def addComment():
    data = request.get_json()
    return Response().success(CommentService().addComment(Comment.decode(data)))

@comment.route('/delete', methods=['GET'])
def deleteComment():
    id = request.args.get("id")
    return Response().success(CommentService().deleteComment(id))


